﻿@model AexoManager.Models.DespieceViewModel
@{
    ViewBag.Title = "DespieceDetalle";
    Layout = "~/Views/Shared/_Template.cshtml";
}
@section ClientScripts {
    <link rel='stylesheet' type='text/css' href='~/Content/assets/plugins/form-nestable/jquery.nestable.css' />
    <script type='text/javascript' src='~/Content/assets/plugins/form-nestable/jquery.nestable.min.js'></script>
    <script type='text/javascript'>
        $(function () {
            $('#despiece').nestable({
                group: 1
            });

            $("#btnCancelar").click(function () {
                $("#formPrincipal").attr("action", "@Url.Content("~/")Despiece/");
                $("#formPrincipal").submit();
            });

        });

        function detalleDespiece(idParte, idProducto) {
            $("#IdProducto").val(idProducto);
            $("#IdPartePadre").val(idParte);
            //alert("hola");
            $("#formPrincipal").attr("action", "@Url.Content("~/")Despiece/Parte");
            $("#formPrincipal").submit();
        }
        /*
        function buildItem(item) {

            var html = "<li class='dd-item' data-id='" + item.IdParte + "' id='" + item.IdParte + "'>";
            html += "<div class='dd3-content'><a href='javascript:detalleDespiece(" + item.Parte.IdParte + "," + +item.Producto.IdProducto + ");'>" + item.Parte.Descripcion + " / Cantidad: " + item.Cantidad + "</a></div>";

            if (item.Child) {

                html += "<ol class='dd-list'>";
                $.each(item.Child, function (index, sub) {
                    html += buildItem(sub);
                });
                html += "</ol>";

            }

            html += "</li>";

            return html;
        }

        */
    </script>
}
<div id="page-content">
    <div id='wrap'>
        <div id="page-heading">
            <ol class="breadcrumb">
                <li class='active'><a href="@Url.Content("~/")">Despiece</a></li>
                <li class='active'><a href="@Url.Content("~/")">Index</a></li>
            </ol>

            <h1>Partes</h1>
        </div>
        <div class="container">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <h4>Despiece del producto: @Html.Raw(ViewBag.DescripcionProducto) </h4>
                </div>
                @using (Html.BeginForm("Nuevo", "Despiece", FormMethod.Post, new { @id = "formPrincipal", @class = "form-horizontal" }))
                {
                    @Html.HiddenFor(m => m.IdPartePadre)
                    @Html.HiddenFor(m => m.IdProducto)
                    <div class="panel-body collapse in">
                        <div class="cf nestable-lists">
                            <div id="despiece">
                                <ul class="dd-list">@DespieceHelper.buildItem(ViewBag.ArbolDespiece)</ul>
                            </div>
                        </div>
                    </div>

                }
                <div class="panel-footer">
                    <div class="row">
                        <div class="pull-right">
                            <div class="btn-toolbar">
                                <button id="btnAceptar" class="btn-primary btn">Aceptar</button>
                                <button id="btnCancelar" class="btn-primary btn">Cancelar</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <!-- container -->
    </div>
    <!--wrap -->
</div>
<!-- page-content -->